<!--
 * @Author       : xiaowu wwl093000@163.com
 * @Date         : 2023-04-20 13:38:18
 * @LastEditTime : 2023-05-05 15:55:06
 * @LastEditors  : xiaowu wwl093000@163.com
 * @FilePath     : /erp-admin-ui/src/views/workorder/submit/index.vue
 * @Description  : -
-->
<template>
  <div class="app-container" v-loading="loading">
    <el-alert :title="title" type="warning" show-icon :closable="false"></el-alert>
    <div class="card-wrapper">
      <div class="card-wrapper-header">提交工单</div>
      <div class="card-wrapper-content">
        <el-form :model="form" ref="form" :rules="rules" label-width="300px">
          <el-form-item label="问题分类" prop="type">
            <!-- <el-cascader filterable v-model="form.categoryId" :options="categoryList"
              :props="{ value: 'id', label: 'name', emitPath: false }" :show-all-levels="false" clearable /> -->
            <el-select v-model="form.type" clearable>
              <el-option
                v-for="dict in dict.type.erp_work_order_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value*1"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="问题标题" prop="subject">
            <el-input v-model="form.subject" placeholder="" style="width: 60%;"></el-input>
          </el-form-item>
          <el-form-item label="问题描述" prop="content">
            <!-- <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 12 }" v-model="form.content" placeholder=""
              style="width: 60%;"></el-input> -->
              <Editor v-model="form.content" :min-height="192" style="width: 60%;"></Editor>
          </el-form-item>
          <div class="button-box">
            <el-button type="primary" :loading="buttonLoading" @click="submit">提交工单</el-button>
            <el-button @click="reset">重置</el-button>
          </div>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import { addWorkOrder } from "@/api/workorder/index";
export default {
  name: "workOrderSubmit",
  dicts: ['erp_work_order_type'],
  data() {
    return {
      // 遮罩层
      loading: false,
      form: {
        status: '0'
      },
      rules: {
        type: [
          { required: true, trigger: "blur", message: "必填项不能为空" }
        ],
        subject: [
          { required: true, trigger: "blur", message: "必填项不能为空" }
        ],
        content: [
          { required: true, trigger: "blur", message: "必填项不能为空" }
        ]
      },
      categoryList: [],
      buttonLoading: false,
      title: `请提交准确的的信息以帮助我们排查问题。请到消息中心订阅“工单信息”提醒消息。工单处理时间为: 工作日 9.00-18.00`
    };
  },
  created() {
  },
  methods: {
    // 提交
    submit() {
      this.$refs["form"].validate((valid, obj) => {
        if (valid) {
          this.buttonLoading = true;
          this.loading = true;
          addWorkOrder(this.form).then(res => {
            this.$modal.msgSuccess("提交成功");
          }).finally(() => {
            this.loading = false;
            this.buttonLoading = false;
            this.reset();
          });
        } else {
          var a = [];
          for (let key in obj) {
            a.push(obj[key][0].message);
          }
          this.$message({
            message: a[0],
            type: "warning",
          });
          return false;
        }
      })
    },
    // 重置
    reset() {
      this.form = {
        status: '0'
      }
    }
  }
};
</script>

<style lang="scss">
.card-wrapper {
  border: 1px solid #DCDFE6;
  margin: 20px 0;

  .card-wrapper-header {
    background-color: #F5F7FA;
    border-bottom: 1px solid #dfe4ed;
    font-size: 20px;
    color: #909399;
    line-height: 40px;
    padding: 0 15px;
    font-weight: 500;
  }

  .card-wrapper-content {
    padding: 30px 20px;
  }

  .button-box {
    padding-left: 300px;
    margin-top: 15px;
    display: flex;
    align-items: center;
  }
}
</style>